<include file="public@header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:url('Plan/index')}">列表</a></li>
        <li class="active"><a>添加</a></li>
    </ul>
    <form method="post" class="form-horizontal js-ajax-form margin-top-20" action="{:url('Plate/platesaddPost')}">
        <input type="hidden" name="plan_id" value="{$info['id']}">
        <foreach name="$info['coil_id']" item="vo">


            <div class="form-group" id="coil_id_{$vo}">
                <label class="col-sm-1 control-label"><span class="form-required"></span> 钢卷号:</label>
                <div class="col-md-2 col-sm-10">
                    {$coil_id_arr_da[$vo]}
                    <a class="btn btn-xs btn-primary" onclick="addkun({$vo})">钢板入库</a>
                </div>
                <label class="col-sm-1 control-label"><span class="form-required">*</span> 剩余钢卷重量</label>
                <div class="col-md-2 col-sm-10">
                    <input type="text" class="form-control" value="" name="data[{$vo}][weight]">
                </div>
                <label class="col-sm-1 control-label"><span class="form-required">*</span> 退还库位</label>
                <div class="col-md-2 col-sm-10">

                    <input type="text" class="form-control" value="" name="data[{$vo}][kuwei]">
                </div>

            </div>
        </foreach>
        <div class="col-sm-offset-2 col-sm-10">
            <button type="submit" class="btn btn-primary js-ajax-submit">保存</button>
            <a class="btn btn-default" href="{:url('Plan/index')}">返回</a>
        </div>
    </form>

</div>
<script src="/static/js/admin.js"></script>
<script src="/static/js/layer/layer.js"></script>
<script>
    // var coil_count = new Array();

    // <foreach name="$info['coil_id']" item="vo">
    //
    //
    //     coil_count[{$vo}]=100;
    //
    //
    // </foreach>


    coil_count = 100;

    function addkun(id) {
        var plate_id;
        var coilarray = new Array();
        coilarray = {$coilarray};
        var coil_id_arr_da1 = new Array();
        coil_id_arr_da1 = {$coil_id_arr_da1};

        var steel_grade_id_arr = new Array();
        steel_grade_id_arr = {$steel_grade_id_arr};

        var ht_id_arr = new Array();
        ht_id_arr = {$ht_id_arr};

        var company_id_arr = new Array();
        company_id_arr = {$company_id_arr};

        var grade_id_arr = new Array();
        grade_id_arr = {$grade_id_arr};



        $.ajax({
            type: "POST",
            url: "{:url('plate/getname')}",
            contentType: "application/json", //如果提交的是json数据类型，则必须有此参数,表示提交的数据类型
            // dataType: "json", //表示返回值类型，不必须

                success(res) {
                    // console.log(res)
                    plate_id = res.data


                    // id="div_is_starting_price_' + id + '_' + coil_count[id] + '"
                    //
                    html = '<table class="table table-hover table-bordered table-list"  id="div_is_starting_price_' + id + '_' + coil_count + '">' +
                        ' <tr>' +
                        '<td>类型:</td>' +
                        '<td> <select name="post[' + coil_count + '][type]" class="form-control" id="'+coil_count+'type" onchange="selectchange('+coil_count+')"> \n' +
                        '                    <option value="0">请选择</option>\n' +
                        '                    <option\n' +
                        '                    <if isset($vo.type)&&$vo.type=="1">selected</if>\n' +
                        '                    value="1">成品库</option>\n' +
                        '                    <option\n' +
                        '                    <if isset($vo.type)&&$vo.type=="2">selected</if>\n' +
                        '                    value="2">实验库</option>\n' +
                        '                    <option\n' +
                        '                    <if isset($vo.type)&&$vo.type=="3">selected</if>\n' +
                        '                    value="3">废料库</option>\n' +
                        '                    <option\n' +
                        '                    selected\n' +
                        '                    value="4">半成品库</option>\n' +
                        '                    <option\n' +
                        '                    <if isset($vo.type)&&$vo.type=="5">selected</if>\n' +
                        '                    value="5">头尾库</option>\n' +
                        '                    <option\n' +
                        '                    <if isset($vo.type)&&$vo.type=="6">selected</if>\n' +
                        '                    value="6">封闭库</option>\n' +
                        '                    <option\n' +
                        '                    <if isset($vo.type)&&$vo.type=="9">selected</if>\n' +
                        '                    value="9">样品库</option>\n' +
                        '                </select></td>' +
                        '<td>钢卷号:</td>' +
                        '<td>' + coil_id_arr_da1[id] + '' +
                        ' <input  type="hidden" class="form-control" value="' + id + '" name="post[' + coil_count + '][coil_id]"></td>' +
                        '<td>成品牌号:</td>' +
                        '<td>' + grade_id_arr[{$info['grade_id']}] + '' +
                        ' <input  type="hidden" class="form-control" value="{$info['grade_id']}" name="post[' + coil_count + '][grade_id]"></td>' +
                    '<td>原料钢种:</td>' +
                    '<td>' + steel_grade_id_arr[{$info['steel_grade_id']}] + '' +
                    ' <input  type="hidden" class="form-control" value="{$info['steel_grade_id']}" name="post[' + coil_count + '][steel_id]"></td>' +
                    '<td>合同号:</td>' +
                    '<td>' + ht_id_arr[{$info['ht_id']}] + '' +
                    ' <input  type="hidden" class="form-control" value="{$info['ht_id']}" name="post[' + coil_count + '][ht_id]"></td>' +
                    '</tr>' +
                    '<tr>' +
                    '<td>捆包号:</td>' +
                    '<td> <input placeholder="" type="text" id="'+coil_count+'name" value="' + plate_id + '" class="form-control" name="post[' + coil_count + '][name]"></td>' +
                    '<td>张数:</td>' +
                    '<td> <input placeholder="" type="text" class="form-control" name="post[' + coil_count + '][sheets]"></td>' +
                    '<td>厚:</td>' +
                    '<td> <input placeholder="" type="text" class="form-control" value="{$info['d']}" name="post[' + coil_count + '][d]"></td>' +
                    '<td>宽:</td>' +
                    '<td> <input placeholder="" type="text" class="form-control" value="{$info['w']}" name="post[' + coil_count + '][w]"></td>' +
                    '<td>长:</td>' +
                    '<td> <input placeholder="" type="text" class="form-control" value="{$info['h']}" name="post[' + coil_count + '][h]"></td>' +
                    '</tr><tr>' +
                    '<td>库位:</td>' +
                    '<td > <input placeholder="" type="text" class="form-control"  name="post[' + coil_count + '][kuwei]"></td>' +
                    '<td>重量:</td>' +
                    '<td > <input placeholder="" type="text" class="form-control"  name="post[' + coil_count + '][weight]"></td>' +

                    '<td>备注:</td>' +
                    '<td colspan="4"> <input placeholder="" type="text" class="form-control"  name="post[' + coil_count + '][remark]"></td>' +
                    '<td>归属:</td>' +
                    '<td > <input placeholder="" type="text" class="form-control" readonly value="{$info['companytype']}" name="post[' + coil_count + '][companytype]"></td>' +
                    '<td><a class="btn btn-xs btn-danger" onClick="remove(\'div_is_starting_price_' + id + '_' + coil_count + '\')">移除</a></td>' +
                    '</tr></table>';
                    idss = '#coil_id_' + id
                    jQuery(idss).append(html);
                    coil_count++

                }
            }
        )


    }
    function selectchange(count){
        // alert(count+'type');
        id='#'+count+'type';
        var type = $(id).val()
        // alert(type);
        if (type>0){
            $.ajax({
                type: "POST",
                url: "{:url('plate/getname')}",
                contentType: "application/json", //如果提交的是json数据类型，则必须有此参数,表示提交的数据类型
                // dataType: "json", //表示返回值类型，不必须
                data:type,
                success: function (res) {
                    // $("#plate_id").html("");
                    //在原来的页面跳转到下载word模板的页面
                    console.log(res)
                    if (res.code == 1 && res.data != '') {
                        $( '#'+count+'name').val(res.data);

                    }
                },
                error: function (data) {
                    alert("钢板接口请求失败，请联系管理员");
                }
            });
        }
    }

    function remove(ids) {
        console.log(ids)
        ids = "#" + ids;
        jQuery(ids).remove();
        // $("#div1").empty();
    }
</script>
</body>
</html>